//
//  CHSViewController.m
//  CAISegmentedPageController
//
//  Created by 海参 on 09/15/2022.
//  Copyright (c) 2022 海参. All rights reserved.
//

#import "CHSViewController.h"
#import <CAISegmentedPageController/CAISegmentedPageControllerKit.h>
#import "SellerOrderAllController.h"

@interface CHSViewController ()<CAISegmentedPageControllerDelegate>

@property (nonatomic, copy) NSArray *segTitles;
@property (nonatomic, strong) NSMutableArray *dataMArray;
@property (nonatomic, strong) CAISegmentedPageController *segPageController;

@end

@implementation CHSViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUI];
    [self setData];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

- (void)setUI{
    self.navigationItem.title = @"我的优惠券";
    
    [self addChildViewController:self.segPageController];
    [self.view addSubview:self.segPageController.view];
    
    self.segTitles = @[@"未使用", @"已使用", @"已过期"];
    self.segPageController.segmentTitles = self.segTitles;
   
    for (int i = 0; i < self.segTitles.count; i++) {
        SellerOrderAllController *vc = [[SellerOrderAllController alloc] init];
        vc.status = [NSString stringWithFormat:@"%@",@(i)];
        [self.dataMArray addObject:vc];
    }
    self.segPageController.viewControllers = self.dataMArray;
    
    self.segPageController.view.frame = CGRectMake(0, 88, CGRectGetWidth(UIScreen.mainScreen.bounds), CGRectGetHeight(UIScreen.mainScreen.bounds)-88);
}

- (void)setData{
    [self.segPageController setSelectedPageIndex:[self.selectStatus integerValue] animated:YES];
}


#pragma mark - 

- (NSMutableArray *)dataMArray
{
    if (!_dataMArray)
    {
        NSMutableArray *mArray = [NSMutableArray array];
        _dataMArray = mArray;
    }
    return _dataMArray;
}

- (CAISegmentedPageController *)segPageController
{
    if (!_segPageController)
    {
        CAISegmentedPageController *view = [[CAISegmentedPageController alloc]init];
        view.segmentHeight = 46;
        view.segmentMinimumItemSpacing = 73;
        view.segmentEdgeInset = UIEdgeInsetsMake(0,36, 0, 36);
//        view.segmentTitleColor = [UIColor caiColorWithHexString:@"#666666"];
//        view.segmentSelectedTitleColor = [UIColor caiColorWithHexString:@"#FF6A00"];
        view.segmentFont = [UIFont systemFontOfSize:14];
        view.segmentSelectedFont = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        view.widthStyle = CAISegmentedControlSegmentItemWidthStyleFixed;
        view.delegate = self;
        _segPageController = view;
    }
    return _segPageController;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

